//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CAUDIOIC_H__
#define __CAUDIOIC_H__

#include <ddk.h>
#include "drvassistant.h"
#include "nu_api.h"
#include <elaaudio.h>

#include "CFileReader.h"
#include "CFIFOPlayBuffer.h"

typedef enum
{
	INPUT_MIC,
	INPUT_VIN,
	INPUT_AUX
}RecorderInputType;

typedef enum
{
	FIH_REC_AUDIO_TYPE_AMR=0,
	FIH_REC_AUDIO_TYPE_MP3=1,
	//FIH_REC_AUDIO_TYPE_AVI=2,
	FIH_REC_AUDIO_TYPE_WAVE=4
}FIH_RecorderAudioType;

typedef enum
{
	MEDIA_FIFO=1,
	MEDIA_FILE=2,
	MEDIA_FILE_FAST=3,
	MEDIA_RINGTONE=4
}DataMedia_en;			// Don't change the sequence of handle mode

typedef enum
{
	FIH_AUD_TYPE_MP3=1,
	FIH_AUD_TYPE_AMR=2,
	//FIH_AUD_TYPE_MIDI=3,
	//FIH_AUD_TYPE_AVI=4,
	//FIH_AUD_TYPE_AAC=5,
	FIH_AUD_TYPE_WAVE=6
}FIH_PlayerAudioType;

typedef enum
{
    FIH_MED_FIFO=1,
    FIH_MED_FILE=2,
    FIH_MED_FILE_FAST=3,
    FIH_MED_RINGTONE=4,
    FIH_MED_IIS=5
}FIH_MediaType;

#define _MAX_PATH     260

#define FIFO_RECORDER_BUFFER_SIZE 0x3000

class CAudioIC : public CDeviceDriver {
public:
    CARAPI Read(
        /* [in] */ Int64 u64Offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 offset,
        /* [in] */ const MemoryBuf &buffer,
        /* [out] */ Int32* pBytesWritten,
        /* [out] */ IEvent** ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 controlCode,
        /* [in] */ const MemoryBuf &inBuffer,
        /* [out] */ MemoryBuf* pOutBuffer,
        /* [out] */ IEvent** ppCompletionEvent);

    virtual void Dispose();

    CAudioIC()
            :m_AppPath(0),
            m_CurrentPath(0),
            m_MediaType(0),
            m_MediaMode(0),
            m_EQValue(0),
            m_volume(5),
            m_RecType(0),
            m_RecMode(0),
            m_RecInputType(0),
            m_nLength(0){
                *m_RecFileName = '\0';
                m_pFIFOPlayBuffer = NULL;
                m_RecordFlag = 0;
                m_RecordThreadFlag = 1;
                m_pRecordWritePoint = NULL;
                m_pRecordWriteSize = 0;
                m_recordbuffer = NULL;
                m_pIRecordThread = NULL;
                m_RecFifoOnly = 0;
            }

    DzMutex   m_lock;
    long m_AppPath;
    long m_CurrentPath;
    int m_MediaType;
    int m_MediaMode;
    int m_EQValue;
    Int8 m_volume;

    int m_RecType;
    int m_RecMode;
    int m_RecInputType;

    unsigned long m_nLength;
    char m_RecFileName[_MAX_PATH];
    DzEvent m_PlayerCallbackEvent;
    DzEvent m_RecorderCallbackEvent;
    DzEvent m_RecordEvent;
    int m_RecordFlag;
    int m_RecordThreadFlag;
    unsigned char *m_pRecordWritePoint;
    Uint32 m_pRecordWriteSize;
    Byte *m_recordbuffer;
    IThread *m_pIRecordThread;

    CFIFOPlayBuffer *m_pFIFOPlayBuffer;
    CFileReader m_FileReader;

    int m_RecFifoOnly;
};

#endif // __CAUDIOIC_H__
